<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-profile"></i> 工资调整
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-table
                    :data="tableData"
                    border
                    class="achievement"
                    @selection-change="handleSelectionChange"
                    header-cell-class-name="table-header"
                    ref="multipleTable"
            >
                <el-table-column label="员工姓名" prop="name"></el-table-column>
                <el-table-column label="员工工号" prop="jobNumber"></el-table-column>
                <el-table-column label="合同名称" prop="contractName"></el-table-column>
                <el-table-column label="合同类型" prop="contractType"></el-table-column>
            </el-table>
        </div>
        <el-button style="float:right" v-print="">打印</el-button>
        <div class="pagination">
            <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="currentPage1"
                    :page-size="pageSize"
                    :total="pageTotal"
                    @current-change="handleCurrentChange1"
            ></el-pagination>
        </div>
    </div>
</template>

<script>
    import { fetchData } from '../../api/check';
    export default {
        name: 'achievement',
        data() {
            return {
                query: {
                    name: '',
                    jobNumber: '',
                    contractName: '',
                    contractType: ''
                },
                //页索引
                pageIndex: 0,
                //每一页的条数
                pageSize: 5,
                //当前页码
                currentPage1: 0,
                //总条数
                pageTotal: 0,
                tableData: [],
                tableDatas: [],
                multipleSelection: [],
                editVisible: false,
                form: {},
                idx: -1,
                id: -1
            };
        },
        created() {
            this.getData();
        },
        methods: {
            // 获取数据
            getData() {
                fetchData(this.query).then(res => {
                    console.log(res);
                    let _this = this;
                    _this.tableDatas = res;
                    _this.currentPage1 = 1;
                    if (_this.tableDatas.length > Number(_this.pageSize)) {
                        for (let i = 0; i < Number(_this.pageSize); i++) {
                            _this.tableData.push(_this.tableDatas[i]);
                        }
                    } else {
                        _this.tableData = _this.tableDatas;
                    }
                    _this.pageTotal = _this.tableDatas.length;
                });
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleCurrentChange1: function(currentPage) {
                let i;
                this.tableData = [];
                //前端分页,直接取值
                this.currentPage1 = currentPage;
                //从哪个开始
                const from = (currentPage - 1) * this.pageSize;
                console.log('from:' + from);
                if (this.tableDatas.length - from >= this.pageSize) {
                    for (i = from; i < from + this.pageSize; i++) {
                        this.tableData.push(this.tableDatas[i]);
                    }
                } else {
                    for (i = from; i < this.tableDatas.length; i++) {
                        this.tableData.push(this.tableDatas[i]);
                    }
                }
            }
        }
    }
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .table {
        width: 100%;
        font-size: 14px;
    }
    .red {
        color: #ff0000;
    }
    .mr10 {
        margin-right: 10px;
    }
    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
    }
</style>
